<template>
	<!-- 设备添加 -->
	<div>
		<div class="edit-top">
			添加充电模块
			<i class="el-icon-close" @click='cancel'></i>
		</div>
		<div class="edit-content">
			<div class="edit-title">模块信息</div>
			<div class="edit-item">
				<label>设备名称：</label><input v-model="info.name" type="text" />
			</div>
			<div class="edit-item">
				<label>设备编号：</label>
				<input v-model="info.code" type="text" />
			</div>	
			<div class="edit-item">
				<label>所属站点：</label>
				<select v-model="info.stationId">
					<option :value="item.id" v-for="(item,idx) in station_list" :key="idx">{{item.name}}</option>
				</select>
			</div>			
			<div class="edit-item">
				<label>货架号：</label>
				<input v-model="info.shelfNumber" type="text" />
			</div>
			<div class="edit-item">
				<label>IP地址：</label>
				<input v-model="info.ipAddress" type="text" />
			</div>
			<div class="edit-item">
				<label>设备型号：</label>
				<input v-model="info.model" type="text" />
			</div>
			<div class="edit-item">
				<label>生产厂家：</label>
				<input v-model="info.manufacturer" type="text" />
			</div>
		</div>
		<div class="edit-bottom">
			<span @click="cancel">取消</span>
			<el-button type="primary" @click="save">保存</el-button>
		</div>
	</div>
</template>

<script>
	import Global from '@/components/Global.vue'
	export default {
		data() {
			return {
				info: {
					name: '',
					code:'',
					stationId:'',
					ipAddress:'',
					model:'',
                    manufacturer:'',
					shelfNumber:'',
					
				},
				station_list:[]
			}
		},
		mounted() {
			this.get_station_list()
		},
		methods: {
			cancel(){
                this.$emit('saveAdd')
			},
			/* 换电站列表 */
			get_station_list() {
				var self = this;
				this.$axios.post(this.$global.serverIp + 'station/station/findPage', {
						"limit": "10000",
						"page": "1"
					})
					.then(function(res) {
						if (res != '') {
							var list = res.data.list;
							list.splice(0, 0, { 'id': '', 'name': '请选择' })
							self.station_list = list
							self.info.stationId = list[0].id
						}
				
					})
			},
			save(){
				if(this.info.name == ''){
					this.$popup.open('设备名称不能为空')
					return;
				}
				if(this.info.code == ''){
					this.$popup.open('设备编号不能为空')
					return;
				}
				if(this.info.stationId == ''){
					this.$popup.open('所属站点不能为空')
					return;
				}
				if(this.info.shelfNumber == ''){
					this.$popup.open('货架号不能为空')
					return;
				}
				var self = this;
				this.$axios.post(this.$global.serverIp + 'station/equipmentCharger/save', {
						"name": self.info.name,
						"code": self.info.code,
						"stationId": self.info.stationId,
						"shelfCode": self.info.shelfNumber,
						"ipAddress": self.info.ipAddress,
						"manufacturer":self.info.manufacturer,
					    "model":self.info.model
				}).then(res =>{
					this.$popup.open('添加成功')
					this.$emit('saveAdd',2)
				})
			},
		}
	}
	import '@/assets/css/edit.css'
</script>
